<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>会员充值</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        #thumb-box {
            position: relative;
        }

        #thumb {
            width: 200px;
            height: 290px;
            position: absolute;
            left: 328px;
            top: -252px;
            display: none;
        }
    </style>
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">前台系统</a>
        <a>
          <cite>会员充值</cite></a>
      </span>
</div>
<div class="x-body" style="margin: 100px 200px">
    <div class="layui-row">
        <form class="layui-form layui-col-md14 x-so" onsubmit="return false;">
            <div class="layui-inline">
                <lable class="layui-form-label">电话号码：</lable>
                <input type="text" name="keywordPhone" id="keywordPhone" value="${registerMember.memberPhone}"
                       placeholder="请输入电话号码" autocomplete="off" maxlength="11" class="layui-input"
                       lay-verify="keywordPhone">
            </div>
            <button class="layui-btn" id="btn-seach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <div class="layui-inline" id="memberInfo" STYLE="text-align: center">
        <div class="layui-input-inline">
            <input type="hidden" class="layui-input">
        </div>
    </div>
    <form class="layui-form" id="rechargeForm" onsubmit="return false">
        <input type="hidden" id="memberId" value="${registerMember.memberId}">
        <div class="layui-form-item">
            <label for="memberName" class="layui-form-label">
                <span class="x-red">*</span>会员名：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="memberName" name="memberName" required=""
                       autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="memberRoleName" class="layui-form-label">
                <span class="x-red">*</span>会员类型：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="memberRoleName" name="memberRoleName" required=""
                       autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="memberMoney" class="layui-form-label">
                <span class="x-red">*</span>余额：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="memberMoney" name="memberMoney" required=""
                       autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="memberCount" class="layui-form-label">
                <span class="x-red">*</span>积分：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="memberCount" name="memberCount" required=""
                       autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="rechargeMoney" class="layui-form-label">
                <span class="x-red">*</span>充值金额：
            </label>
            <div class="layui-input-inline">
                <input type="number" id="rechargeMoney" name="rechargeMoney" required="" lay-verify="rechargeMoney"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="workerName" class="layui-form-label">
                <span class="x-red">*</span>操作员：
            </label>
            <div class="layui-input-inline">
                <input type="hidden" id="workerId" value="${worker.workerId}">
                <input type="text" id="workerName" name="workerName" value="${worker.workerName}" readonly
                       autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label for="workerPassword" class="layui-form-label">
                <span class="x-red">*</span>密码确认：
            </label>
            <div class="layui-input-inline">
                <input type="password" id="workerPassword" name="workerPassword" required="" lay-verify="password"
                       autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">充值</button>
            <button type="reset" class="layui-btn layui-btn-primary" onclick="$('#keywordPhone').val('')">重置</button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        form.verify({
            password: [/(.+){6,12}$/, '密码必须6到12位'],
            rechargeMoney: [/^([1-9]\d*|0)(\.\d{1,2})?$/, '充值金额不能为空且最多保留两位小数！'],
            keywordPhone:[/^1[0-9]{10}/,'请输入正确的电话号码']
        });


        //监听提交
        form.on('submit(add)', function (data) {
            var memberId = $('#memberId').val();
            var memberMoney = $('#memberMoney').val();
            var rechargeMoney = $('#rechargeMoney').val();
            //发异步，把数据提交给java
            $.ajax({
                type: "post",
                url: "${pageContext.request.contextPath}/foreground?m=recharge",
                data: {
                    memberId: memberId,
                    memberMoney: memberMoney,
                    rechargeMoney: rechargeMoney,
                    workerId: $('#workerId').val(),
                    workerPassword: $('#workerPassword').val(),
                },
                dataType: "json",
                success: function (data) {
                    layer.msg(data.msg, function () {
                        if (data.code === 200) {
                            location.replace('${pageContext.request.contextPath}/foreground?m=memberRechargePage');
                        }
                    });

                }
            });
            return false;
        });

        if ($('#memberId').val()!=null && $('#memberId').val()!=""){
            changeValue();
        }

        function changeValue(){
            $("#memberName").empty();
            $("#memberRoleName").empty();
            $("#memberMoney").empty();
            $("#rechargeMoney").empty();
            $("#memberCount").empty();
            // 获取搜索的数据
            var memberPhone = $("input[name=keywordPhone]").val();
            $.ajax({
                type: "post",
                url: "${pageContext.request.contextPath}/foreground?m=findMember",
                data: {memberPhone: memberPhone},
                dataType: "json",
                success: function (data) {
                    if (data.code === 200) {
                        if (data.data.memberId != null) {
                            $("#memberName").val(data.data.memberName);
                            $("#memberId").val(data.data.memberId);
                            $("#memberRoleName").val(data.data.memberRole.memberRoleName + " (" + data.data.memberRole.memberRoleCount + "折)");
                            $("#memberMoney").val(data.data.memberMoney + "元");
                            $("#memberCount").val(data.data.memberCount + "积分");
                        }
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });

        }

        // 搜索
        $("#btn-seach").click(function () {
            changeValue();
        });
    });
</script>

</body>

</html>